package com.emergency.flyinfo;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Timer;
import java.util.TimerTask;
import com.emergency.Pinyin.AutoCompleteSource;
import com.emergency.Pinyin.SearchAdapter;
import com.emergency.service.RoadNetWebService;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.text.format.Time;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;

public class FlyInfo extends Activity {
	private static final String TAG = "DataLineActivity";
	boolean clearThread=false;
	//private Handler handler;
	
	boolean showprograss=true;
	//String webserviceString="00:15,Y87940,扬子江航空快运有限公司,T2,杭州,已于 00:49 起飞;00:45,8Y9045,中国邮政航空公司,T2,南京,已于 00:52 起飞";
	//String webserviceString2="00:45,8Y9045,中国邮政航空公司,T2,南京,已于 00:52 起飞;00:15,Y87940,扬子江航空快运有限公司,T2,杭州,已于 00:49 起飞";
	String trColor;
	TableLayout  tableLayout;
	private String SearchFlyString;
	ProgressDialog pd;
	Spinner inoutport_status;
	Spinner starttime,endtime;
	Timer timer=new Timer();
	private TimerTask task;
	 public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.flylinereportlayout);
	        ConnectivityManager cwjManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
	        
	        pd = ProgressDialog.show(this, "数据加载中...", "正在加载数据,请稍候...", true,false);
            
	         tableLayout=(TableLayout) findViewById(R.id.flytable);
	       // ArrayAdapter<CharSequence> arrayadapter=ArrayAdapter.createFromResource(this, R.array.Country, android.R.layout.simple_dropdown_item_1line);
	        SearchAdapter  destnationadapter = new SearchAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, AutoCompleteSource.getDestnation(),SearchAdapter.ALL);//速度优先   
	        SearchAdapter  flycompanyadapter = new SearchAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, AutoCompleteSource.getFlyCompany(),SearchAdapter.ALL);//速度优先   
	        AutoCompleteTextView destnation=(AutoCompleteTextView)findViewById(R.id.destination);
	        destnation.setAdapter(destnationadapter);
	        Time time = new Time("GMT+8");
			 time.setToNow();
			 int hour=time.hour+8;
	         starttime=(Spinner) findViewById(R.id.start_time);
	         starttime.setSelection(hour+1);
			
			
			 endtime=(Spinner) findViewById(R.id.end_time);
			 endtime.setSelection(hour+1);
			 
	        
	         inoutport_status=(Spinner) findViewById(R.id.in_out_port);
	         mudidiStringTextView=(TextView) findViewById(R.id.destString);
	         inoutportString=inoutport_status.getSelectedItem().toString();
	         inoutport_status.setOnItemSelectedListener(new OnItemSelectedListener() {

					@Override
					public void onItemSelected(AdapterView<?> arg0, View arg1,
							int position, long arg3) {
						
						// TODO Auto-generated method stub
						if(position==0){
							
							mudidiStringTextView.setText("出发地");
							inoutportStatus="A";
						}else if(position==1){
							mudidiStringTextView.setText("目的地");
							inoutportStatus="D";
						}
					}

					@Override
					public void onNothingSelected(AdapterView<?> arg0) {
						// TODO Auto-generated method stub
						
					}
				});

	        AutoCompleteTextView flycompany=(AutoCompleteTextView)findViewById(R.id.flycompany);
	        flycompany.setAdapter(flycompanyadapter);
	      /* String[]  webserviceStringValue=webserviceString.split(";");
	        for(int i=0;i<webserviceStringValue.length;i++){
	        	 if(i%2==0){
					 
					 trColor="#d8e7f2";
				 }else{
					 trColor="#FFFFFF";
					 
				 }
	        	addRow(webserviceStringValue[i]);
	        	
	        }*/
	        
	        RadioGroup radioGroup=(RadioGroup) findViewById(R.id.radioGroup);
			 mRadio1 = (RadioButton) findViewById(R.id.unlimit); 
			 mRadio2 = (RadioButton) findViewById(R.id.delay); 
			 mRadio3 = (RadioButton) findViewById(R.id.cancel); 
			radioGroup.setOnCheckedChangeListener(mChangeRadio);
			  
			NetworkInfo info = cwjManager.getActiveNetworkInfo();
			if (info != null && info.isAvailable()) {// 判断当前设备是否可以联网
				
					 new Thread(){

					    	public void run(){
					    		
					    		if(isConnByHttp()){
					    			
					    			task = new TimerTask() {

										@Override
										public void run() {
											// TODO Auto-generated method stub
											FlyString = RoadNetWebService.getFlyTextString("getRealAirportInfo");
											Message message = new Message();
											message.what = 1;
											handler.sendMessage(message);
										}
									
									};
									timer.schedule(task, 500, 300000);
							
								 Time time = new Time("GMT+8");
								 time.setToNow();
								 int hour=time.hour;
								 /*System.out.println("-----"+hour);*/
								 String starttime,endtime;
								 if((hour+8)>=10){
									 
									 starttime=(hour+8)+":00";
									 
								 }else{
									 
									 starttime="0"+(hour+8)+":00";
								 }
								 
								 if((hour+9)>=10){
									 
									 endtime=(hour+9)+":00";
									 
								 }else{
									 
									 endtime="0"+(hour+9)+":00";
								 }
								 
								SearchFlyString=RoadNetWebService.getNearAirPortInfo("queryAirPortInfo","","","",starttime,endtime,"","A");
								if(SearchFlyString.equals("anyType{}")){
									
									SearchFlyString="当前搜索条件内无数据!";
								}
								Message message = new Message();
								message.what = 0;
								handler.sendMessage(message);
								
								//System.out.println("搜索航班信息:"+SearchFlyString);
								
					    		}else{
									
									CannotConnectServ();//这个方法写在了子县城里
									Message message = new Message();
									message.what = 2;
									handler.sendMessage(message);
									
								}
					    	}
						     
					      }.start();
				
			}else{
				
				CannotConnectNet();
				Message message = new Message();
				message.what = 3;
				handler.sendMessage(message);
			}
	     
	       
	    }
	 
	/* public int getTimeCurrent(int Time){
		 int position=0;
		 String starttime;
		 if((Time+8)>=10){
			 
			 starttime=(Time+8)+":00";
			 
		 }else{
			 
			 starttime="0"+(Time+8)+":00";
		 }
		 
		 if(starttime.equals("00:00")){
			 
			 position=1;
		 }else if(starttime.equals("01:00")){
			 
			 position=2;
		 }else if(starttime.equals("02:00")){
			 
			 position=3;
		 }else if(starttime.equals("03:00")){
			 position=4;
			 
		 }else if(starttime.equals("04:00")){
			 position=5;
			 
		 }else if(starttime.equals("05:00")){
			 
			 position=6;
		 }else if(starttime.equals("06:00")){
			 position=6;
			 
		 }else if(starttime.equals("07:00")){
			 
			 position=7;
		 }else if(starttime.equals("08:00")){
			 position=8;
			 
		 }else if(starttime.equals("09:00")){
			 
			 position=9;
		 }else if(starttime.equals("10:00")){
			 position=10;
			 
		 }else if(starttime.equals("11:00")){
			 
			 position=11;
		 }else if(starttime.equals("12:00")){
			 position=12;
			 
		 }else if(starttime.equals("13:00")){
			 
			 position=13;
		 }else if(starttime.equals("14:00")){
			 
			 position=14;
		 }else if(starttime.equals("15:00")){
			 position=15;
			 
		 }else if(starttime.equals("16:00")){
			 
			 position=16;
		 }else if(starttime.equals("17:00")){
			 position=17;
			 
		 }else if(starttime.equals("18:00")){
			 position=18;
			 
		 }else if(starttime.equals("19:00")){
			 
			 position=19;
		 }else if(starttime.equals("20:00")){
			 position=0;
			 
		 }else if(starttime.equals("21:00")){
			 position=0;
			 
		 }else if(starttime.equals("22:00")){
			 position=0;
			 
		 }else if(starttime.equals("23:00")){
			 position=0;
			 
		 }else if(starttime.equals("24:00")){
			 position=0;
			 
		 }
		 
		 return position;
	 }*/
	 
	 
	 public void addRow(String dataSource){
		 String time= null, flyNum = null, flyCompany= null, houjilou= null, destnation= null,status= null;
		 String[] datasourceValue=dataSource.split(",");
		 int fontSize=22;
		 for(int i=0;i<datasourceValue.length;i++){
			
			 if(i==0){
				 
				 time=datasourceValue[i];
				 
			 }else if(i==1){
				 
				 flyNum=datasourceValue[i];
				 
			 }else if(i==2){
				 
				 flyCompany=datasourceValue[i];
				 
			 }else if(i==3){
				 
				 houjilou=datasourceValue[i];
				 
			 }else if(i==4){
				 
				 destnation=datasourceValue[i];
				 
			 }else if(i==5){
				 
				 status=datasourceValue[i];
			 }
			 
		 }
		
	        TableRow tr = new TableRow(this);
	        
	        tr.setLayoutParams(new LayoutParams(
                 LayoutParams.FILL_PARENT, 
                 LayoutParams.WRAP_CONTENT));
	        tr.setBackgroundColor(Color.parseColor(trColor));
	        tr.setPadding(0, 10, 0, 10);
	        TextView tx1=new TextView(this);
	       
	        tx1.setText(time);
	        tx1.setTextColor(Color.BLACK);
	        tx1.setTextSize(fontSize);
	        tx1.setGravity(Gravity.CENTER);
	        
	        tr.addView(tx1);
	        
	        
	        TextView tx2=new TextView(this);
	      
	        tx2.setText(flyNum);
	        tx2.setEllipsize(TextUtils.TruncateAt.MARQUEE);
	        tx2.setWidth(50);
	        tx2.setFocusable(true);
	        tx2.setSingleLine(true);
	        tx2.setHorizontallyScrolling(true);
	        tx2.setMarqueeRepeatLimit(6);
	        tx2.setTextColor(Color.BLACK);
	        tx2.setTextSize(fontSize);
	        tx2.setFocusableInTouchMode(true);
	        tr.addView(tx2);
	        
	        TextView tx3=new TextView(this);
	      
	        tx3.setText(flyCompany);
	        tx3.setTextColor(Color.BLACK);
	        tx3.setTextSize(fontSize);
	        tx3.setGravity(Gravity.CENTER);
	        
	        tr.addView(tx3);
	        
	        TextView tx4=new TextView(this);
	       
	        tx4.setText(houjilou);
	        tx4.setTextColor(Color.BLACK);
	        tx4.setTextSize(fontSize);
	        tx4.setGravity(Gravity.CENTER);
	        
	        tr.addView(tx4);
	        
	        TextView tx5=new TextView(this);
	       
	        tx5.setText(destnation);
	        tx5.setTextColor(Color.BLACK);
	        tx5.setTextSize(fontSize);
	        tx5.setGravity(Gravity.CENTER);
	        
	        tr.addView(tx5);
	        
	        TextView tx6=new TextView(this);
	       
	        tx6.setText(status);
	        tx6.setTextColor(Color.BLACK);
	        tx6.setTextSize(fontSize);
	        tx6.setGravity(Gravity.CENTER);
	        
	        tr.addView(tx6);
	        
	        tableLayout.addView(tr,new TableLayout.LayoutParams(
                 LayoutParams.FILL_PARENT, 
                 LayoutParams.WRAP_CONTENT));
	        
	 }
	 
	 
	 public void addTitleRow(String dataSource){
		 String time= null, flyNum = null, flyCompany= null, houjilou= null, destnation= null,status= null;
		 String[] datasourceValue=dataSource.split(",");
		 int fontSize=22;
		 for(int i=0;i<datasourceValue.length;i++){
			
			 if(i==0){
				 time=datasourceValue[i];
				 
			 }else if(i==1){
				 
				 flyNum=datasourceValue[i];
			 }else if(i==2){
				 flyCompany=datasourceValue[i];
				 
			 }else if(i==3){
				 
				 houjilou=datasourceValue[i];
			 }else if(i==4){
				 
				 destnation=datasourceValue[i];
			 }else if(i==5){
				 
				 status=datasourceValue[i];
			 }
			 
		 }
		
	        TableRow tr = new TableRow(this);
	        
	        tr.setLayoutParams(new LayoutParams(
                 LayoutParams.FILL_PARENT, 
                 LayoutParams.WRAP_CONTENT));
	
	        tr.setBackgroundDrawable(getResources().getDrawable(R.drawable.tablehead));
	        TextView tx1=new TextView(this);
	       
	        tx1.setText(time);
	        tx1.setTextColor(Color.WHITE);
	        tx1.setTextSize(fontSize);
	        tx1.setGravity(Gravity.CENTER_HORIZONTAL);
	        tx1.setPadding(5, 5, 5, 5);
	        tr.addView(tx1);
	        
	        
	        TextView tx2=new TextView(this);
	      
	        tx2.setText(flyNum);
	       
	        tx2.setWidth(50);
	        tx2.setTextColor(Color.WHITE);
	        tx2.setTextSize(fontSize);
	        tx2.setGravity(Gravity.CENTER_HORIZONTAL);
	        tx2.setPadding(5, 5, 5, 5);
	        tr.addView(tx2);
	        
	        TextView tx3=new TextView(this);
	      
	        tx3.setText(flyCompany);
	        tx3.setTextColor(Color.WHITE);
	        tx3.setTextSize(fontSize);
	        tx3.setGravity(Gravity.CENTER_HORIZONTAL);
	        tx3.setPadding(5, 5, 5, 5);
	        tr.addView(tx3);
	        
	        TextView tx4=new TextView(this);
	       
	        tx4.setText(houjilou);
	        tx4.setTextColor(Color.WHITE);
	        tx4.setTextSize(fontSize);
	        tx4.setGravity(Gravity.CENTER_HORIZONTAL);
	        tx4.setPadding(5, 5, 5, 5);
	        tr.addView(tx4);
	        
	        TextView tx5=new TextView(this);
	       
	        tx5.setText(destnation);
	        tx5.setTextColor(Color.WHITE);
	        tx5.setTextSize(fontSize);
	        tx5.setGravity(Gravity.CENTER_HORIZONTAL);
	        tx5.setPadding(5, 5, 5, 5);
	        tr.addView(tx5);
	        
	        TextView tx6=new TextView(this);
	       
	        tx6.setText(status);
	        tx6.setTextColor(Color.WHITE);
	        tx6.setTextSize(fontSize);
	        tx6.setGravity(Gravity.CENTER_HORIZONTAL);
	        tx6.setPadding(5, 5, 5, 5);
	        tr.addView(tx6);
	       
	        tableLayout.addView(tr,new TableLayout.LayoutParams(
                 LayoutParams.FILL_PARENT, 
                 LayoutParams.WRAP_CONTENT));
	        
	 }
	 
	 private Handler handler=new Handler(){
		 @Override
			// 当有消息发送出来的时候就执行Handler的这个方法
			public void handleMessage(Message msg) {
				super.handleMessage(msg);
				// 处理UI
				switch (msg.what) {
				case 0:
					handler.post(searchFlyInfo);
					break;
				case 1:
					handler.post(linetextUI);
					break;
				case 2:
					builder.create().show();
					
					break;
				case 3:
					builder2.create().show();
					break;
				}

			}
	 };
	 AlertDialog.Builder builder2;
	 public void CannotConnectNet() {// 当服务器连接不上的时候 就提示用户 并关闭主程序。

		 	builder2= new AlertDialog.Builder(
					FlyInfo.this);
			builder2.setTitle("错误");
			builder2.setMessage("无法连接互联网，请稍候重试");
			builder2.setCancelable(false); // 禁止取消键
			builder2.setNegativeButton("确认", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					finish();
				}
			});
			

		}
	 
	AlertDialog.Builder builder;
	
	 public void CannotConnectServ() {
		  
    		   
			builder = new AlertDialog.Builder(
					FlyInfo.this);
			builder.setTitle("错误");
			builder.setMessage("无法连接服务器，请稍候重试");
			builder.setCancelable(false); // 禁止取消键
			builder.setNegativeButton("确认", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					pd.dismiss();
				}
			});
			
		}
	 public boolean isConnByHttp(){
	        boolean isConn = false;
	        URL url;
	        HttpURLConnection conn = null;
	        try {
	        	//交通委网
	        	//url=new URL("http://172.24.186.187:8887/phone/webService");
	        	//外网
	        	 //url=new URL("http://114.251.193.190:8899/phone");
	        	//内网
	        	
	        	//url = new URL("http://172.18.18.203:8199/phone/");
	        	//url = new URL("http://172.18.18.203:8199/phone/");
	        	//url = new URL("http://10.10.149.7:8080/phone/");
	        	url=new URL("http://172.28.18.2:7777/phone/");
	            conn = (HttpURLConnection)url.openConnection();
	            conn.setConnectTimeout(1000*6); 
	            if(conn.getResponseCode()==200){
	                isConn = true;
	            }
	            
	        } catch (MalformedURLException e) {
	            // TODO Auto-generated catch block
	            e.printStackTrace();
	        }catch (IOException e) {
	            // TODO Auto-generated catch block
	            e.printStackTrace();
	        }finally{
	            conn.disconnect();
	        }
	        return isConn;
	    }
	 
	 @Override
		protected void onStart() {
			super.onStart();
			Log.e(TAG, "start onStart~~~");
		}

		@Override
		protected void onRestart() {
			super.onRestart();
			Log.e(TAG, "start onRestart~~~");
			
		}

		@Override
		protected void onResume() {
			super.onResume();
			Log.e(TAG, "start onResume~~~");
		}

		@Override
		protected void onPause() {
			super.onPause();
			Log.e(TAG, "start onPause~~~");
			
			
		}

		@Override
		protected void onStop() {
			
			super.onStop();
			if(builder2!=null){
				
				builder2.create().dismiss();
			}
			if(builder!=null){
				
				builder.create().dismiss();
			}
			pd.cancel();
			Log.e(TAG, "start onStop~~~");
		}

		@Override
		protected void onDestroy() {
			super.onDestroy();
			timer.cancel();
			finish();
			Log.e(TAG, "start onDestroy~~~");
		}
		
		
		
		Runnable linetextUI = new Runnable() {
			@Override
			public void run() {
				
					 initLinesText();
				

			}
	
		};
		
		Runnable searchFlyInfo = new Runnable() {
			@Override
			public void run() {
				
				queryFlyInfoTable(SearchFlyString);
				pd.dismiss();
			}
	
		};
	    

	 String FlyString;
	  public void initLinesText(){//初始化曲线文本信息
		 
		  if(FlyString==null){
				Toast toast = Toast.makeText(getApplicationContext(),
						"由于网络问题，无法获取航班信息~~!", Toast.LENGTH_LONG);
				toast.setGravity(Gravity.CENTER, 0, 0);
				toast.show();
				
			}else{
				
				  //System.out.println("---------航班详细信息-------"+FlyString);
				    String[] SingleRoadValue =FlyString.split(",");
				    DynamicSetTextTool(R.string.intoportfly,Integer.parseInt( SingleRoadValue[0]), R.id.inportfly);
					DynamicSetTextTool(R.string.outportfly, Integer.parseInt(SingleRoadValue[1].toString()), R.id.outportfly);
					DynamicSetTextTool(R.string.futureinportfly, Integer.parseInt(SingleRoadValue[2].toString()), R.id.futureinportfly);
					DynamicSetTextTool(R.string.futureoutportfly, Integer.parseInt(SingleRoadValue[3].toString()), R.id.futureoutportfly);
			    	//DynamicSetTextTool(R.string.refreshTime1,SingleRoadValue[4].toString(),R.id.refresh1);
			    	DynamicSetTextTool(R.string.intoportpeople,Integer.parseInt(SingleRoadValue[6].toString()),R.id.intoportpeople);
			    	DynamicSetTextTool(R.string.outportpeople,Integer.parseInt(SingleRoadValue[7].toString()),R.id.outportpeople);
			    	DynamicSetTextTool(R.string.sumpeople,Integer.parseInt(SingleRoadValue[8].toString()),R.id.sumpeople);
			    	DynamicSetTextTool(R.string.futureinportpeople,Integer.parseInt(SingleRoadValue[9].toString()),R.id.futureinportpeople);
			    	//DynamicSetTextTool(R.string.refreshTime2,SingleRoadValue[10].toString(),R.id.refreshTime2);
			    	DynamicSetTextTool(R.string.delayfly,Integer.parseInt(SingleRoadValue[12].toString()),R.id.delayfly);
			    	DynamicSetTextTool(R.string.cancelfly,Integer.parseInt(SingleRoadValue[13].toString()),R.id.cancelfly);
			}
		  
	    }
	    
	    public void DynamicSetTextTool(int stringId,Object changeText,int viewId){//动态文本工具方法
	    	
	    	 String RefreshTime = getResources().getString(stringId);   
	         String FinalRefreshTime = String.format(RefreshTime, changeText);  
	         TextView RefreshTextObject = (TextView) findViewById(viewId);
	         RefreshTextObject.setText(FinalRefreshTime);
	    	
	    }
	    
	    public void queryFlyInfoTable(String searchFlyStrings){
	    	
	    	tableLayout.removeAllViews();
	    	if(mudidiStringTextView.getText().equals("出发地")){
	    		
	    		addTitleRow("计划到港,航班号,航空公司,候机楼,出发地,状态");
	    	}else{
	    		
	    		addTitleRow("计划离港,航班号,航空公司,候机楼,目的地,状态");
	    	}
			
			 String[]  webserviceStringValue=searchFlyStrings.split(";");
			 
		        for(int i=0;i<webserviceStringValue.length;i++){
		        	 if(i%2==0){
						 
						 trColor="#d8e7f2";
						 
					 }else{
						 
						 trColor="#FFFFFF";
						 
					 }
		        	 
		        	 addRow(webserviceStringValue[i]);
		        	 
		        }
	    }
	    public void hideKeyboard(){//隐藏软键盘
	    	
	    	if(getCurrentFocus()!=null)
			{
				((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
				.hideSoftInputFromWindow(getCurrentFocus()
						.getWindowToken(),
						InputMethodManager.HIDE_NOT_ALWAYS); 
			}
	    }
	    RadioButton mRadio1,mRadio2,mRadio3;
	    String flyStatusString="0";
	    String startTimeString,endTimeString;
	    String inoutportStatus="A";
	    String inoutportString;
	    TextView mudidiStringTextView;
	    public void Search(View view){
	    	hideKeyboard();
	    	pd.show();
			EditText flyNum=(EditText) findViewById(R.id.flynum);
			final String flyNumString=flyNum.getText().toString();
			
			AutoCompleteTextView destination=(AutoCompleteTextView) findViewById(R.id.destination);
			final String destnationString=destination.getText().toString();
			
			AutoCompleteTextView flycompany=(AutoCompleteTextView) findViewById(R.id.flycompany);
			final String flycompanyString=flycompany.getText().toString();
			
			 startTimeString=starttime.getSelectedItem().toString();
			 endTimeString=endtime.getSelectedItem().toString();
			 
			 Time time = new Time("GMT+8");
			 time.setToNow();
			 int hour=time.hour;
			 hour=hour+8;
			
			if(startTimeString.equals("起始时间")&&endTimeString.equals("结束时间")){
				
				if(hour>=10){
					
					startTimeString=hour+":00";
					
				}else{
					
					startTimeString="0"+hour+":00";
					
				}
				
				if((hour+1)>=10){
					
					endTimeString=(hour+1)+":00";
				}else{
					
					endTimeString="0"+(hour+1)+":00";
					
				}
				
			}else if(startTimeString.equals("起始时间")&&!endTimeString.equals("结束时间")){
				String[] endHourStrings;
				endHourStrings=endTimeString.split(":");
				int startHour=Integer.parseInt(endHourStrings[0])-1;
				
				if(startHour>=10){
					
					startTimeString=startHour+":00";
					
				}else if(startHour<10&&startHour>0){
					
					startTimeString="0"+startHour+":00";
					
				}else{
					
					startTimeString="00:00";
				}
				
			}else if(!startTimeString.equals("起始时间")&&endTimeString.equals("结束时间")){
				String[] startHourStrings;
				startHourStrings=startTimeString.split(":");
				int endHour=Integer.parseInt(startHourStrings[0])+1;
				//System.out.println(endHour);
				if(endHour>=10){
					
					endTimeString=endHour+":00";
					
				}else if(endHour<10&&endHour>0){
					
					endTimeString="0"+endHour+":00";
					
				}else{
					
					endTimeString="01:00";
				}
			}
			String senddata=flyNumString+","+destnationString+","+flycompanyString+","+startTimeString+","+endTimeString+","+flyStatusString+","+inoutportStatus;
			//System.out.println("senddata:"+senddata);
			new Thread(){
				
				public void run(){
					
					SearchFlyString=RoadNetWebService.getNearAirPortInfo("queryAirPortInfo",flyNumString,destnationString,flycompanyString,startTimeString,endTimeString,flyStatusString,inoutportStatus);
					if(SearchFlyString!=null){
						if(SearchFlyString.equals("anyType{}")){
							
							SearchFlyString="当前搜索条件内无数据!";
						}
					}
					
					Message message = new Message();
					message.what = 0;
					handler.sendMessage(message);
					
				}
				
			}.start();
	    }
	    
	    private RadioGroup.OnCheckedChangeListener mChangeRadio = new RadioGroup.OnCheckedChangeListener() { 
	        @Override
	        
	        public void onCheckedChanged(RadioGroup group, int checkedId) {
	        
	            // TODO Auto-generated method stub 
	        	if (checkedId == mRadio1.getId()) { 
	                // 把mRadio1的内容传到mTextView1 
					flyStatusString="0";//不限
	            } else if (checkedId == mRadio2.getId()) { 
	                // 把mRadio2的内容传到mTextView1 
	            	flyStatusString="1";//取消
	            } else if(checkedId == mRadio3.getId()){
	            	
	            	flyStatusString="2";//延误
	            }

	        } 
	    }; 

	    public void gotoReport(View view){
	    	
	    	startActivity(new Intent(FlyInfo.this, FlyReport.class));
	    }
	
}
